package com.cloud.class05.resp;

import lombok.Data;

/**
 * @ClassDescription:
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2024/4/9 16:07
 */
@Data//<T>的作用，申明泛型
public class ResultData<T> {
    //    结果状态，具体状态码参见枚举类ReturnCodeEnum.java
    private String code;
    //    T 使用泛型，可以指定任意类型
    private String message;
    private T data;
    private long timestamp;

    public ResultData() {
        this.timestamp = System.currentTimeMillis();
    }

    //<T>的作用，申明参数泛型
    public static <T> ResultData<T> success(T data) {
        ResultData resultData = new ResultData();
        resultData.setCode(ReturnCodeEnum.RC200.getCode());
        resultData.setMessage(ReturnCodeEnum.RC200.getMessage());
        resultData.setData(data);
        return resultData;
    }

    public static <T> ResultData<T> fail(String code, String message) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(code);
        resultData.setMessage(message);
        return resultData;
    }
//   public  static class AAA {
//        private String name;
//        static int age;
//
//
//    }
//public static void main(String[] args) {
//    long l = System.currentTimeMillis();
//    Date date = new Date(l);
//
//    System.out.println(date);
//}


}
